<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>添加用户</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport"
          content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" th:href="@{../static/css/weadmin.css}">
</head>

<body>
<div class="weadmin-body">
    <form id="form" class="layui-form">

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">上传头像</label>
            <div class="layui-form-label">
                <button type="button" class="layui-btn" id="upload-button">
                    <i  class="layui-icon">&#xe67c;</i>上传图片
                </button>
            </div>
        </div>

        <div class="layui-form-item layui-form-text">
            <label class="layui-form-label">图片预览</label>
            <div class="layui-input-block">
                <img id="image" alt="" style="width: 200px;height: 200px;">
            </div>
        </div>

        <div class="layui-form-item">
            <label for="username" class="layui-form-label">
                <span class="we-red">*</span>用户名
            </label>
            <div class="layui-input-inline">
                <input type="text" id="username" name="username" required="" lay-verify="required" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_email" class="layui-form-label">
                <span class="we-red">*</span>邮箱
            </label>
            <div class="layui-input-inline">
                <input type="text" id="L_email" name="email" required="" lay-verify="email" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                <span class="we-red">*</span>将会成为您唯一的登入名
            </div>
        </div>
        <div class="layui-form-item">
            <label for="phone" class="layui-form-label">
                <span class="we-red">*</span>手机
            </label>
            <div class="layui-input-inline">
                <input type="text" id="phone" name="telephone" required="" lay-verify="phone" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="1" title="男" checked>
                <input type="radio" name="sex" value="0" title="女">
            </div>
        </div>
        <div class="layui-form-item" >
            <label class="layui-form-label">角色</label>
            <div class="layui-input-block">
                <select name="role" lay-verify="required">
                    <option value="1">管理员</option>
                    <option value="2">评委</option>
                    <option value="3">参赛选手</option>
                </select>
            </div>
        </div>

        <div class="layui-form-item">
            <label for="L_pass" class="layui-form-label">
                <span class="we-red">*</span>密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_pass" name="password" required="" lay-verify="pass" autocomplete="off"
                       class="layui-input">
            </div>
            <div class="layui-form-mid layui-word-aux">
                6到16个字符
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label">
                <span class="we-red">*</span>确认密码
            </label>
            <div class="layui-input-inline">
                <input type="password" id="L_repass" name="repass" required="" lay-verify="repass" autocomplete="off"
                       class="layui-input">
            </div>
        </div>
        <div class="layui-form-item">
            <label for="L_repass" class="layui-form-label"></label>
            <button id="btn" class="layui-btn" lay-filter="add" lay-submit="">增加</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </form>
</div>
<script th:src="@{../../static/layui/layui.js}"></script>
<script th:src="@{../../static/mysource/js/jquery-3.3.1.min.js}"></script>
<script th:src="@{../../static/js/admin.js}"></script>
<script th:src="@{../../static/js/add.js}" type="text/javascript"></script>

<script type="text/javascript">

    layui.use('upload', function(){
        var upload = layui.upload;
        //获得layui里的jquery
        var $ = layui.$;

        //执行实例
        var uploadInst = upload.render({
            elem: '#upload-button' //绑定元素
            ,url: '/upload/image' //上传接口
            ,done: function(res){
                if(res.code == 1) {
                    //成功
                    layer.msg(res.msg);
                    //首先我们要获得我们上传之后的图片的访问路径
                    var imagePath = res.data.src;
                    console.log(imagePath)
                    $("#image").attr("src",imagePath)
                }else {
                    //失败了
                    layer.msg(res.msg);
                }
            }
            ,error: function(){
                //请求异常回调
            }
        });
    });


</script>


</body>

</html>